using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Tools;
using Pixysoft.Framework.Verifications;
using Pixysoft.Framework.Noebe;
using Pixysoft.Weblications.Sango.Entities;

namespace Pixysoft.Weblications.Sango.Environment
{
    public class PtyPartyTitleHelper
    {
        private static List<Pty_Partytitle> orms = new List<Pty_Partytitle>();

        public static void initialize()
        {
            orms = SettingHelper.GetNoebe().EntityNoebeCommand.Select<Pty_Partytitle>();

            LoggerHelper.Info("initialize Pty_Partytitle.count {0}", orms.Count);
        }

        public static Pty_Partytitle searchByLevel(long level)
        {
            foreach (Pty_Partytitle orm in orms)
            {
                if (orm.Titlelevel == level)
                    return orm;
            }

            throw Exceptions.VerificationFailedException(level);
        }

        public static Pty_Partytitle searchByCode(long code)
        {
            Pty_Partytitle orm = trySearchByCode(code);

            if (orm == null)
                throw Exceptions.VerificationFailedException(code);

            return orm;
        }

        public static Pty_Partytitle trySearchByCode(long code)
        {
            foreach (Pty_Partytitle orm in orms)
            {
                if (orm.Titletypecode == code)
                    return orm;
            }

            return null;
        }

        public static List<Pty_Partytitle> searchAll()
        {
            return orms;
        }

    }
}